<?php
	include_once("../../MasterPages/headerPHPScript.php");
	$SubjectService = new SubjectService();
	$SubjectCode = ISSET($_GET["SubjectCode"]) ? $_GET["SubjectCode"] : "";
	$DeleteFlag = ISSET($_GET["DeleteFlag"]) ? $_GET["DeleteFlag"] : "";
	
	if($DeleteFlag!=""){
		$SubjectService->DeleteSubject($SubjectCode);
	}else{
		$SubjectEntity = new SubjectEntity();
		if(ISSET($_POST["txtSubjectCode"])){
			$SubjectEntity->SubjectCode = $_POST["txtSubjectCode"];
			$update = false;
		}else{
			$SubjectEntity->SubjectCode = $_POST["hiddenSubjectCode"];
			$update = true;
		}
		
		$SubjectEntity->SubjectName = $_POST["txtSubjectName"];
		
		if($update){
			$SubjectService->UpdateSubject($SubjectEntity);
		}else{
			$SubjectService->InsertSubject($SubjectEntity);
		}
	}
	
	header("location:../index.php?page=admin-manage-subject.php");
?>
